package com.white.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.white.bean.UserModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserModelMapper extends BaseMapper<UserModel> {
    String TABLE_NAME = " userModel ";
    String SELECT = "select * from" + TABLE_NAME + "where ";

    @Update("update" + TABLE_NAME + "set views = views + 1 where userId = #{userId} and classifyId = #{classifyId}")
    void viewsInc(Long userId, Long classifyId);

    @Select(SELECT + "userId = #{userId} and classifyId = #{classifyId} limit 1")
    UserModel getUserModel(Long userId, Long classifyId);

    @Update("update" + TABLE_NAME + "set viewDuration = viewDuration + #{seconds} where userId = #{userId} and classifyId = (" +
            "select classifyId from article where articleId = #{articleId})")
    void incViewDuration(Long userId, Long articleId, int seconds);

    @Insert("insert" + TABLE_NAME + "(userId, classifyId) values(#{userId}, #{classifyId})")
    void myCreate(UserModel userModel);

    @Select(SELECT + "userId = #{userId}")
    List<UserModel> searchById(Long userId);
}
